import jmespath
import requests
from loguru import logger

# 删除数据
def select_label():
    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Connection': 'keep-alive',
        'Referer': 'http://124.70.39.201/admin/member/label',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
        'lang': 'zh-cn',
        'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJpc3MiOiIxMjQuNzAuMzkuMjAxIiwiYXVkIjoiMTI0LjcwLjM5LjIwMSIsImlhdCI6MTc0NDYyMDI3NCwibmJmIjoxNzQ0NjIwMjc0LCJleHAiOjE3NDUyMjUwNzQsImp0aSI6IjFfYWRtaW4ifQ.pkbJuCK4tERkIJQs01SMsJoVXVSbRSGjD6HMQaUXJ44',
        # 'Cookie': 'AJS.conglomerate.cookie="|streams.view.10003=list-view"',
    }

    params = {
        'page': '1',
        'limit': '10',
        'label_name': '',
    }
    response = requests.get('http://124.70.39.201/adminapi/member/label', params=params, headers=headers)
    return response.json()

def delete_label(d_id):
    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Connection': 'keep-alive',
        'Origin': 'http://124.70.39.201',
        'Referer': 'http://124.70.39.201/admin/member/label',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
        'lang': 'zh-cn',
        'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJpc3MiOiIxMjQuNzAuMzkuMjAxIiwiYXVkIjoiMTI0LjcwLjM5LjIwMSIsImlhdCI6MTc0NDYyMDI3NCwibmJmIjoxNzQ0NjIwMjc0LCJleHAiOjE3NDUyMjUwNzQsImp0aSI6IjFfYWRtaW4ifQ.pkbJuCK4tERkIJQs01SMsJoVXVSbRSGjD6HMQaUXJ44',
        # 'Cookie': 'AJS.conglomerate.cookie="|streams.view.10003=list-view"',
    }

    response = requests.delete(f'http://124.70.39.201/adminapi/member/label/{d_id}', headers=headers, verify=False)

while True:
    ids = jmespath.search("data.data[*].label_id", select_label())
    # print(type(ids))
    if len(ids) == 0:
        break
    logger.debug(f"删除id:{ids[0]}")
    delete_label(ids[0])